package com.chanzany.interview_secondary.jvm.jvm_04_OOM;

import java.util.ArrayList;
import java.util.List;

/**
 GC回收时间过长时会抛出OutOfMemoryError.
 即超过98%的时间用来做GC但是回收了不到2%的堆内存

 JVM参数
 -Xms10m -Xmx10m -XX:MaxDirectMemorySize=5m
 */
public class GCOverHeadLimitExceededError {
    public static void main(String[] args) {
        int i = 0;
        List<String> list = new ArrayList<>();
        try {
            while (true){
                list.add(String.valueOf(i++).intern());
            }
        }catch (Throwable e){
            System.out.println("*******i*******:"+i);
            e.printStackTrace();
        }
        //java.lang.OutOfMemoryError: GC overhead limit exceeded
    }
}
